﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.DAL;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public  class DictTypeBLL
    {
        private DictTypeDAL udal= new DictTypeDAL();

        public IEnumerable<DictType> Query(string DictTypeName, out int Total, int PageSize = 10, int PageIndex = 1)
        {
            var data = udal.GetAll();
            Total = data.Count();
            if (!string.IsNullOrEmpty(DictTypeName))
            {
                data = data.Where(o => o.DictTypeName.Contains(DictTypeName));
            }
            return data.OrderBy(o => o.CreateTime).Skip(PageSize * (PageIndex - 1)).Take(PageSize);
        }
        public DictType Get(int id) 
        {
            return udal.GetOne(o => o.Id == id);
        }
        public bool Add(DictType entity) 
        {
        return udal.Add(entity);
        }
        public bool Update(DictType entity ) 
        {
        return udal.Update(entity);
        }
        public bool Delete(int id) 
        {
         DictType entity = new DictType();
            entity.Id = id;
            udal._dbContext.Entry(entity).State = System.Data.Entity.EntityState.Unchanged;
            entity.IsDelete = 1;
            return udal.SaveChanges();
        }
    }
}
